package questionLibrary;
/**
 * Class QuestionInfo is used to store information about question and about possible answers on it.
 *
 * @version 1.44 21 jun 2012
 * @author Anton Samarsky
 * @author Vladimir Vyshko
 */
public class QuestionInfo {
    
    private String question;
    
    private String[] answer;
    
    private OrganInfo[] organEffect;
    
    
    /**
     * This is constructor, that sets question and answers.
     * @param question is question that will copy to inner string.
     * @param answers is array of strings, each of which is possible answer.
     */
      public QuestionInfo(String question, String...answers) {
    	
    	this.question = new String(question);

    	answer = answers.clone();
    	
        organEffect = new OrganInfo[answer.length];
        for (int i = 0; i < organEffect.length; i++)
            organEffect[i] = new OrganInfo();

    }
    
    /**
     * This method writes effects of every answer on chosen organ.
     * Warning! Count of answers can be less then count of bonuses in params bonus.
     * @param organ is organ, which will get effects of answers.
     * @param param is parameter of organ, which will be changed (for example, energy of brain).
     * @param bonus is number of points (with sign + or -), which characterize some positive or negative effect (0 is neutral effect).
     * @throws IllegalArgumentException if it was specified illegal count of bonuses.
     */
    public void insertEffects(int organ, int param, int...bonus) {

        if (answer.length != bonus.length)
            throw new IllegalArgumentException("Wrong count of arguments! Count of effects must be equal count of answers.");
        
        for (int numberOfAnswer = 0; numberOfAnswer < answer.length; numberOfAnswer++){
            
            organEffect[numberOfAnswer].setParameter(organ, param, bonus[numberOfAnswer]);
        }
    }
    
    /**
     * This method is used for getting text of question.
     * @return text of question.
     */
    public String getQuestion() {
        return new String(question);
    }
    
    /**
     * This method is used for getting text of answers.
     * @return text of answers.
     */
    public String[] getAnswers() {
        return answer.clone();
    }
    
    /**
     * This method returns effect for some parameter param for organ organ.
     * @param organ is organ, which will get effects of answers.
     * @param param is parameter of organ, which will be changed (for example, energy of brain).
     * @param answer_number is number of answers which affects on some effect of some organ.
     * @return summary effect of all answers for some param of some organ.
     */
    public int getEffect(int organ, int param, int...answerNumber) {
        
        int result = 0;
        for (int numberOfAnswer:answerNumber){
            result += organEffect[numberOfAnswer].getParameter(organ, param);
        }
        return result;
    }
    
    /**
     * This simple method returns count of answers, which was specified in constructor.
     * @return count of answers.
     */
    public int getCountOfAnswers() {
        return answer.length;
    }
    
    /**
     * This method is used for getting entire text (with question and answers) to show it on the screen.
     * @return string which may be shown on the screen.
     */
     public String toString() {
       StringBuilder questionWithAnswers = new StringBuilder();
       questionWithAnswers.append(question);
       questionWithAnswers.append("\nPossible answers:\n");
       for (int numberOfAnswer = 0; numberOfAnswer < answer.length; numberOfAnswer++){
          questionWithAnswers.append(numberOfAnswer);
          questionWithAnswers.append(". ");
          questionWithAnswers.append(answer[numberOfAnswer]);
          questionWithAnswers.append("\n");
       }
       return questionWithAnswers.toString();
    }
    
}